package com.luckymore.ydd.app.funcs.funclist;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.base.control.MActivitySupport;
import com.base.model.ContextDefinition;
import com.base.util.DateUtil;
import com.base.view.selfview.NoScrollGridView;
import com.luckymore.ydd.app.R;
import com.luckymore.ydd.app.db.MQuestionFragment;
import com.luckymore.ydd.app.funcs.contact.ContactActivity;
import com.luckymore.ydd.app.funcs.essence.EssenceActivity;
import com.luckymore.ydd.app.funcs.noteAssist.NoteBackupActivity;
import com.luckymore.ydd.app.funcs.noteAssist.NotePrintActivity;
import com.luckymore.ydd.app.funcs.person.PersonActivity;

import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * Created by yjh on 15-3-12.
 */
public class MainFuncsFragment extends MQuestionFragment {
    private TextView monthTv;
    private TextView yearTv;
    private TextView dayTv;
    private TextView functions_square_text;
    private NoScrollGridView gridView;

    ImageView functions_bg;

    private List<ContextDefinition<Activity>> funcList;
    private MainFuncsAdapter adapter;

    @Override
    protected void create(Bundle savedInstanceState) {
        setContentView(R.layout.fragment_functions);

        monthTv = findViewById(R.id.functions_month);
        yearTv = findViewById(R.id.functions_year);
        dayTv = findViewById(R.id.functions_day);
        gridView = findViewById(R.id.functions_grid);
        functions_square_text = findViewById(R.id.functions_square_text);
        functions_bg = findViewById(R.id.functions_bg);

        setShowActionbar(false);

        setImageView(functions_bg, R.drawable.today_background_blur, MActivitySupport.ImageLoaderType.DEFAULT, false);

        monthTv.setText(DateUtil.getMonthSimpleName(new Date()));
        yearTv.setText(DateUtil.getYear(new Date()) + "");
        dayTv.setText(DateUtil.getDay(new Date()) + "");

        funcList = getFuncList();

        adapter = new MainFuncsAdapter(funcList, getMactivity());
        gridView.setAdapter(adapter);

        functions_square_text.setText("考研路上，一路相伴");

    }

    @Override
    public void onResume() {
        super.onResume();
        adapter.notifyDataSetChanged();
    }

    public List<ContextDefinition<Activity>> getFuncList() {
        return Collections.unmodifiableList(Arrays.asList(
                new ContextDefinition<Activity>("精华", R.drawable.function_essence, EssenceActivity.class, getMactivity().setStartType(1)),
//                new ContextDefinition<Activity>("我的收藏", R.drawable.function_essence, EssenceActivity.class, getMactivity().setStartType(2)),
                new ContextDefinition<Activity>("备份", R.drawable.function_backup, NoteBackupActivity.class),
                new ContextDefinition<Activity>("个人中心", R.drawable.function_person_center, PersonActivity.class),
                new ContextDefinition<Activity>("VIP", R.drawable.function_vip, null),
                new ContextDefinition<Activity>("打印", R.drawable.function_print, NotePrintActivity.class),
                new ContextDefinition<Activity>("联系我们", R.drawable.function_contact, ContactActivity.class)
        ));
    }
}
